package cn.enjoy.tool.juc.SimpleThreadPool;

/**
 * @author K
 * @date 2021/7/30 下午5:46
 */
public class ThreadPoolTest {
    public static void main(String[] args) {
        DefaultThreadPool<Runnable> defaultThreadPool = new DefaultThreadPool<>(5, "KThread");
        for (int i = 0; i < 100; i++) {
            int finalI = i;
            defaultThreadPool.execute(() -> System.out.println(finalI + 1));
        }
        System.out.println("===========print===========");
        System.out.println("当前待执行任务数量：" + defaultThreadPool.getJobSize());
        System.out.println("工作线程数量" + defaultThreadPool.getWorkerNum());
        defaultThreadPool.addWorkers(2);
        System.out.println("增加工作线程后的数量" + defaultThreadPool.getWorkerNum());
        defaultThreadPool.removeWorker(2);
        System.out.println("减少工作线程后的数量" + defaultThreadPool.getWorkerNum());
        defaultThreadPool.shutdown();
        System.out.println("关闭线程池");
        System.out.println("未执行任务数量：" + defaultThreadPool.getJobSize());
    }
}
